﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel_Project.Tools.MySqlData_Helps
{
    /// <summary>
    /// 线程异步将指定MySql数据库中的数据返回为DataTable对象以便绑定,返回单个程序集,程序集就是DataTable对象
    /// </summary>
    internal class MySqlDataTable
    {
        /// <summary>
        /// 线程异步获取指定数据库的DataTable对象
        /// </summary>
        /// <param name="Sql">Sql语句,查询MySql指定数据库语句</param>
        /// <param name="SqlConnand">Sql语句,建立连接语句</param>
        /// <returns></returns>
        public async Task<DataTable> GetDataTable(string sqlCommand,string sql)
        {
            DataTable dt = new DataTable();
            using (var conn = new MySqlConnection(sqlCommand))
            {
                //异步建立连接
                await conn.OpenAsync();
                MySqlCommand cmd=new MySqlCommand(sql, conn);
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                adapter.Fill(dt);
            }
            return dt;
        }
    }
}
